package com.imay.live.proto;

import android.content.Context;
import android.text.TextUtils;

import com.imay.live.utils.ToastUtil;
import com.imay.live.BuildConfig;
import com.imay.live.R;

/**
 * Created by chan on 2017/4/10.
 */

public class ErrorResult {
    public static void toastError(Context context, int code) {
        ToastUtil.show(context, getString(context, code));
    }

    public static void toastError(Context context, int code, String message) {
        ToastUtil.show(context, !TextUtils.isEmpty(message) ? message : getString(context, code));
    }

    public static String getString(Context context, int code) {
        String errorString = "";
        if (context != null) {
            String stringName = "error_" + code;
            if (context.getResources() != null) {
                int resId = context.getResources().getIdentifier(stringName, "string", BuildConfig.APPLICATION_ID);
                if (resId == 0) {
                    errorString = context.getString(R.string.error_unknown, code);
                } else {
                    errorString = context.getString(resId);
                }
            }
        }
        return errorString;
    }
}
